package com.hyt.it.ogt.pj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyt.core.base.BaseServiceImpl;
import com.hyt.it.ogt.pj.common.ResponseCode;
import com.hyt.it.ogt.pj.mapper.TotalScoreMapper;
import com.hyt.it.ogt.pj.model.entity.Project;
import com.hyt.it.ogt.pj.model.entity.TotalScore;
import com.hyt.it.ogt.pj.service.IProjectService;
import com.hyt.it.ogt.pj.service.ITotalScoreService;

/**
 * <p>
 * 总分表 服务实现类
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
@Service
public class TotalScoreServiceImpl extends BaseServiceImpl<TotalScoreMapper, TotalScore> implements ITotalScoreService {

    @Autowired
    private TotalScoreMapper totalScoreMapper;

    @Autowired
    private IProjectService projectService;

    @Override
    public List<TotalScore> getGrade(String projectId) {
        List<TotalScore> totalScores = totalScoreMapper.selectGrade(projectId);
        return totalScores;
    }

    @Override
    public Integer calculateScore(String projectId, String userId) {
        if(projectId == null || "".equals(projectId)){
            Project project = projectService.currentProject(userId);
            if(project != null){
                projectId = project.getId();
            }
        }
        if(projectId != null){
            List<TotalScore> toaalScores = totalScoreMapper.calculateScore(projectId);
            this.saveBatch(toaalScores);
        }
        return ResponseCode.SUCCESS;
    }
}
